home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / errors.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-04  |  1.5 KB  |  44 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   4230
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1515
  7.    ClientWidth     =   6720
  8.    Height          =   4635
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4230
  12.    ScaleWidth      =   6720
  13.    Top             =   1170
  14.    Width           =   6840
  15. Attribute VB_Name = "Form1"
  16. Attribute VB_Creatable = False
  17. Attribute VB_Exposed = False
  18. Option Explicit
  19. Private Sub Form_Load()
  20.     Dim db As DATABASE
  21.     Dim dbName As String
  22.     Dim rs As Recordset
  23.     Dim s As String
  24.     On Error GoTo LoadError
  25.   ' Get the database name and open the database.
  26.     dbName = BiblioPath()       ' BiblioPath is a function in READINI.BAS
  27. 10  Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
  28.     ' This statement will cause an error, because there's no such table
  29.     ' as No Such Table.
  30. 20  Set rs = db.OpenRecordset("No Such Table", dbOpenTable)
  31.     ' There is a table named Titles, so this one should work.
  32. 30  Set rs = db.OpenRecordset("Titles", dbOpenTable)
  33.     ' There's no such field as No Such Field, so here's another error.
  34. 40  s = rs![No Such Field]
  35.     ' This causes an error because Year Published only takes numeric values.
  36. 50  rs![Year Published] = "XYZ"
  37.     ' Finally!
  38. 60  End
  39. Exit Sub
  40. LoadError:
  41.     MsgBox "Error #" & Str$(Err.Number) & " at Line " & Str$(Erl) & " - " & Err.Description & " - reported by " & Err.Source
  42. Resume Next
  43. End Sub
  44.